#include "vertex_index_buffer.h"
#include "render_device.h"

c_vertex_buffer9::c_vertex_buffer9(unsigned int length, unsigned long usage, D3DPOOL pool)
{
    BOOST_ASSERT(length != 0);

    HRESULT hr; 
    V(c_render_device9::get_singleton().get_d3d_device_ptr()->CreateVertexBuffer(length, usage, 0, pool, &m_d3d9_vb, 0)); 
}

c_vertex_buffer9::~c_vertex_buffer9()
{
}

void* c_vertex_buffer9::lock(unsigned int offset, unsigned int size, unsigned long flags)
{
    HRESULT hr; 
    void *pdata;
    V(m_d3d9_vb->Lock(offset, size, &pdata, flags)); 

    return pdata;
}

bool c_vertex_buffer9::unlock()
{
    HRESULT hr; 
    V(m_d3d9_vb->Unlock()); 
    
    return SUCCEEDED(hr);
}

//////////////////////////////////////////////////////////////////////////

c_index_buffer9::c_index_buffer9(unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool)
{
    BOOST_ASSERT(length != 0);

    HRESULT hr; 
    V(c_render_device9::get_singleton_ptr()->get_d3d_device_ptr()->CreateIndexBuffer(length, usage, format, pool, &m_d3d9_ib, 0)); 
}

c_index_buffer9::~c_index_buffer9()
{
}
